import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;


public class ComputeSHA {
	public static void main(String[] args) {
		try {
			// Get the message digest
			MessageDigest md = MessageDigest.getInstance("SHA-1");
			md.reset();
			
			// Open the file
			BufferedInputStream f = new BufferedInputStream(new FileInputStream(args[0]));
			int c;
			
			// Update the input in the digest as we read the file
			while ((c = f.read()) != -1) {
				md.update(new Integer(c).byteValue());
			}
			
			// Close the stream
			f.close();
			
			/*
			 * Method of converting to hex string from the following:
			 *   http://www.spiration.co.uk/post/1199/Java-md5-example-with-MessageDigest
			 */
			byte digest[] = md.digest();
			StringBuffer hexString = new StringBuffer();
			for (int i = 0; i < digest.length; i++) {
				hexString.append(Integer.toHexString(0xFF & digest[i]));
			}
			
			System.out.println(hexString);
		} catch (NoSuchAlgorithmException e) {
			e.printStackTrace();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
